//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections;
using System.Web.UI.WebControls;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security;
using DotNetNuke.Security.Profile;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.UI.Utilities;
using DotNetNuke.UI.WebControls;
using DotNetNuke.Common.Lists;
namespace DotNetNuke.Modules.Admin.Users
{
	partial class UserAccounts : Entities.Modules.PortalModuleBase, Entities.Modules.IActionable
	{
		private string _Filter = "";
		private string _FilterProperty = "";
		private int _CurrentPage = 1;
		private ArrayList _Users = new ArrayList();
		protected int TotalPages = -1;
		protected int TotalRecords;
		protected int CurrentPage
		{
			get { return _CurrentPage; }
			set { _CurrentPage = value; }
		}
		protected string Filter
		{
			get { return _Filter; }
			set { _Filter = value; }
		}
		protected string FilterProperty
		{
			get { return _FilterProperty; }
			set { _FilterProperty = value; }
		}
		protected bool IsSuperUser
		{
			get
			{
				if (PortalSettings.ActiveTab.ParentId == PortalSettings.SuperTabId)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}
		protected int PageSize
		{
			get
			{
				object setting = UserModuleBase.GetSetting(UsersPortalId, "Records_PerPage");
				return Convert.ToInt32(setting);
			}
		}
		protected bool SuppressPager
		{
			get
			{
				object setting = UserModuleBase.GetSetting(UsersPortalId, "Display_SuppressPager");
				return Convert.ToBoolean(setting);
			}
		}
		protected int UsersPortalId
		{
			get
			{
				int intPortalId = PortalId;
				if (IsSuperUser)
				{
					intPortalId = Null.NullInteger;
				}
				return intPortalId;
			}
		}
		protected string UserFilter(bool newFilter)
		{
			string page = !string.IsNullOrEmpty(CurrentPage.ToString()) ? "currentpage=" + CurrentPage : "";
			string filterString;
			string filterPropertyString;
			if (!newFilter)
			{
				filterString = !string.IsNullOrEmpty(Filter) ? "filter=" + Filter : "";
				filterPropertyString = !string.IsNullOrEmpty(FilterProperty) ? "filterproperty=" + FilterProperty : "";
			}
			else
			{
				filterString = !string.IsNullOrEmpty(txtSearch.Text) ? "filter=" + Server.UrlEncode(txtSearch.Text) : "";
				filterPropertyString = !string.IsNullOrEmpty(ddlSearchType.SelectedValue.ToString()) ? "filterproperty=" + ddlSearchType.SelectedValue.ToString() : "";
			}
			if (!string.IsNullOrEmpty(filterString))
			{
				filterString += "&";
			}
			if (!string.IsNullOrEmpty(filterPropertyString))
			{
				filterString += filterPropertyString + "&";
			}
			if (!string.IsNullOrEmpty(page))
			{
				filterString += page;
			}
			return filterString;
		}
		protected ArrayList Users
		{
			get { return _Users; }
			set { _Users = value; }
		}
		private ListItem AddSearchItem(string name)
		{
			string propertyName = Null.NullString;
			if (Request.QueryString["filterProperty"] != null)
			{
				propertyName = Request.QueryString["filterProperty"];
			}
			string text = Localization.GetString(name, this.LocalResourceFile);
			if (String.IsNullOrEmpty(text))
				text = name;
			ListItem li = new ListItem(text, name);
			if (name == propertyName)
			{
				li.Selected = true;
			}
			return li;
		}
		private void BindData()
		{
			BindData(null, null);
		}
		private void BindData(string SearchText, string SearchField)
		{
			CreateLetterSearch();
			string strQuerystring = Null.NullString;
			if (!String.IsNullOrEmpty(SearchText))
			{
				strQuerystring += "filter=" + SearchText;
			}
			if (SearchText == Localization.GetString("Unauthorized"))
			{
				Users = UserController.GetUnAuthorizedUsers(UsersPortalId, true, IsSuperUser);
				ctlPagingControl.Visible = false;
			}
			else if (SearchText == Localization.GetString("Deleted"))
			{
				Users = UserController.GetDeletedUsers(UsersPortalId);
				ctlPagingControl.Visible = false;
			}
			else if (SearchText == Localization.GetString("OnLine"))
			{
				Users = UserController.GetOnlineUsers(UsersPortalId);
				ctlPagingControl.Visible = false;
			}
			else if (SearchText == Localization.GetString("All"))
			{
				Users = UserController.GetUsers(UsersPortalId, CurrentPage - 1, PageSize, ref TotalRecords, true, IsSuperUser);
			}
			else if (SearchText != "None")
			{
				switch (SearchField)
				{
					case "Email":
						Users = UserController.GetUsersByEmail(UsersPortalId, SearchText + "%", CurrentPage - 1, PageSize, ref TotalRecords, true, IsSuperUser);
						break;
					case "Username":
						Users = UserController.GetUsersByUserName(UsersPortalId, SearchText + "%", CurrentPage - 1, PageSize, ref TotalRecords, true, IsSuperUser);
						break;
					default:
						Users = UserController.GetUsersByProfileProperty(UsersPortalId, SearchField, SearchText + "%", CurrentPage - 1, PageSize, ref TotalRecords, true, IsSuperUser);
						strQuerystring += "&filterProperty=" + SearchField;
						break;
				}
			}
			if (SuppressPager && ctlPagingControl.Visible)
			{
				ctlPagingControl.Visible = (PageSize < TotalRecords);
			}
			grdUsers.DataSource = Users;
			grdUsers.DataBind();
			ctlPagingControl.TotalRecords = TotalRecords;
			ctlPagingControl.PageSize = PageSize;
			ctlPagingControl.CurrentPage = CurrentPage;
			ctlPagingControl.QuerystringParams = strQuerystring;
			ctlPagingControl.TabID = TabId;
		}
		private void CreateLetterSearch()
		{
			string filters = Localization.GetString("Filter.Text", this.LocalResourceFile);
			filters += "," + Localization.GetString("All");
			filters += "," + Localization.GetString("OnLine");
			filters += "," + Localization.GetString("Unauthorized");
			filters += "," + Localization.GetString("Deleted");
			string[] strAlphabet = filters.Split(',');
			rptLetterSearch.DataSource = strAlphabet;
			rptLetterSearch.DataBind();
		}
		private void DeleteUnAuthorizedUsers()
		{
			try
			{
				UserController.DeleteUnauthorizedUsers(PortalId);
				BindData(Filter, ddlSearchType.SelectedItem.Value);
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}


		/// -----------------------------------------------------------------------------
		/// <summary>
		/// Permanently removes soft-deleted users
		/// </summary>
		/// <history>
		/// 	[aprasad]	02/15/2011	Created
		/// </history>
		/// -----------------------------------------------------------------------------
		private void RemoveDeletedUsers()
		{
			try
			{
				UserController.RemoveDeletedUsers(PortalId);

				BindData(Filter, ddlSearchType.SelectedItem.Value);

				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// Can user delete / remove / restore
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <history>
		/// 	[aprasad]	2/16/2011	Created
		///                       
		/// </history>
		/// -----------------------------------------------------------------------------
		private bool IsCommandAllowed(UserInfo user, string Command)
		{

			bool immageVisibility = !(user.UserID == PortalSettings.AdministratorId) && (!user.IsInRole(PortalSettings.AdministratorRoleName) || (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName))) && !(user.UserID == UserId);

			if ((immageVisibility))
			{
				if ((Command == "Delete"))
				{
					if ((user.IsDeleted))
					{
						immageVisibility = false;
					}
				}
				else if ((Command == "Remove" || Command == "Restore"))
				{
					if ((user.IsDeleted))
					{
						immageVisibility = true;
					}
					else
					{
						immageVisibility = false;
					}
				}
			}

			return immageVisibility;
		}

		public string DisplayAddress(object Unit, object Street, object City, object Region, object Country, object PostalCode)
		{
			string _Address = Null.NullString;
			try
			{
				_Address = Common.Globals.FormatAddress(Unit, Street, City, Region, Country, PostalCode);
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
			return _Address;
		}
		public string DisplayEmail(string Email)
		{
			string _Email = Null.NullString;
			try
			{
				if (Email != null)
				{
					_Email = HtmlUtils.FormatEmail(Email, false);
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
			return _Email;
		}
		public string DisplayDate(System.DateTime UserDate)
		{
			string _Date = Null.NullString;
			try
			{
				if (!Null.IsNull(UserDate))
				{
					_Date = UserDate.ToString();
				}
				else
				{
					_Date = "";
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
			return _Date;
		}
		protected string FormatURL(string strKeyName, string strKeyValue)
		{
			string _URL = Null.NullString;
			try
			{
				if (!String.IsNullOrEmpty(Filter))
				{
					_URL = EditUrl(strKeyName, strKeyValue, "", "filter=" + Filter);
				}
				else
				{
					_URL = EditUrl(strKeyName, strKeyValue);
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
			return _URL;
		}
		protected string FilterURL(string Filter, string CurrentPage)
		{
			string _URL = Null.NullString;
			if (!String.IsNullOrEmpty(Filter))
			{
				if (!String.IsNullOrEmpty(CurrentPage))
				{
					_URL = Common.Globals.NavigateURL(TabId, "", "filter=" + Filter, "currentpage=" + CurrentPage);
				}
				else
				{
					_URL = Common.Globals.NavigateURL(TabId, "", "filter=" + Filter);
				}
			}
			else
			{
				if (!String.IsNullOrEmpty(CurrentPage))
				{
					_URL = Common.Globals.NavigateURL(TabId, "", "currentpage=" + CurrentPage);
				}
				else
				{
					_URL = Common.Globals.NavigateURL(TabId, "");
				}
			}
			return _URL;
		}
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			btnSearch.Click += new System.Web.UI.ImageClickEventHandler(btnSearch_Click);
			grdUsers.ItemCommand += new DataGridCommandEventHandler(grdUsers_ItemCommand);
			grdUsers.ItemDataBound += new DataGridItemEventHandler(grdUsers_ItemDataBound);

			if (Request.QueryString["CurrentPage"] != null)
			{
				CurrentPage = Convert.ToInt32(Request.QueryString["CurrentPage"]);
			}
			if (Request.QueryString["filter"] != null)
			{
				Filter = Request.QueryString["filter"];
			}
			if (Request.QueryString["filterproperty"] != null)
			{
				FilterProperty = Request.QueryString["filterproperty"];
			}
			if (String.IsNullOrEmpty(Filter))
			{
				object setting = UserModuleBase.GetSetting(UsersPortalId, "Display_Mode");
				DisplayMode mode = (DisplayMode)setting;
				switch (mode)
				{
					case DisplayMode.All:
						Filter = Localization.GetString("All");
						break;
					case DisplayMode.FirstLetter:
						Filter = Localization.GetString("Filter.Text", this.LocalResourceFile).Substring(0, 1);
						break;
					case DisplayMode.None:
						Filter = "None";
						break;
				}
			}
			foreach (DataGridColumn column in grdUsers.Columns)
			{
				bool isVisible;
				string header = column.HeaderText;
				if (String.IsNullOrEmpty(header) || header.ToLower() == "username")
				{
					isVisible = true;
				}
				else
				{
					string settingKey = "Column_" + header;
					object setting = UserModuleBase.GetSetting(UsersPortalId, settingKey);
					isVisible = Convert.ToBoolean(setting);
				}
				if (object.ReferenceEquals(column.GetType(), typeof(ImageCommandColumn)))
				{
					isVisible = this.IsEditable;
					ImageCommandColumn imageColumn = (ImageCommandColumn)column;
					if (imageColumn.CommandName == "Delete")
					{
						imageColumn.OnClickJS = Localization.GetString("DeleteItem");
					}
					else if (imageColumn.CommandName == "Remove")
					{
						imageColumn.OnClickJS = Localization.GetString("RemoveItem");
					}
					if (imageColumn.CommandName == "Edit")
					{
						string formatString = EditUrl("UserId", "KEYFIELD", "Edit", UserFilter(false));
						formatString = formatString.Replace("KEYFIELD", "{0}");
						imageColumn.NavigateURLFormatString = formatString;
					}
					if (imageColumn.CommandName == "UserRoles")
					{
						if (IsHostMenu)
						{
							isVisible = false;
						}
						else
						{
							string formatString = EditUrl("UserId", "KEYFIELD", "User Roles", UserFilter(false));
							formatString = formatString.Replace("KEYFIELD", "{0}");
							imageColumn.NavigateURLFormatString = formatString;
						}
					}
					if (!String.IsNullOrEmpty(imageColumn.CommandName))
					{
						imageColumn.Text = Localization.GetString(imageColumn.CommandName, this.LocalResourceFile);
					}
				}
				column.Visible = isVisible;
			}
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			try
			{
				AddActionHandler(ModuleAction_Click);
				if (!Page.IsPostBack)
				{
					ddlSearchType.Items.Add(AddSearchItem("Username"));
					ddlSearchType.Items.Add(AddSearchItem("Email"));
					ProfilePropertyDefinitionCollection profileProperties = ProfileController.GetPropertyDefinitionsByPortal(PortalId, false);
					foreach (ProfilePropertyDefinition definition in profileProperties)
					{
						ListController controller = new ListController();
						ListEntryInfo imageDataType = controller.GetListEntryInfo("DataType", "Image");
						if (imageDataType == null || definition.DataType == imageDataType.EntryID)
						{
							break;
						}
						ddlSearchType.Items.Add(AddSearchItem(definition.PropertyName));
					}
					Localization.LocalizeDataGrid(ref grdUsers, this.LocalResourceFile);
					BindData(Filter, ddlSearchType.SelectedItem.Value);
					if ((!String.IsNullOrEmpty(Filter) && Filter.ToUpper() != "NONE") && !String.IsNullOrEmpty(FilterProperty))
					{
						txtSearch.Text = Filter;
						ddlSearchType.SelectedValue = FilterProperty;
					}
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private void ModuleAction_Click(object sender, ActionEventArgs e)
		{
			switch (e.Action.CommandArgument)
			{
				case "Delete":
					DeleteUnAuthorizedUsers();
					break;
				case "Remove":
					RemoveDeletedUsers();
					break;
			}
		}
		private void btnSearch_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e)
		{
			CurrentPage = 1;
			txtSearch.Text = txtSearch.Text.Trim();
			Response.Redirect(Common.Globals.NavigateURL(TabId, "", UserFilter(true)));
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// grdUsers_ItemCommand runs when any command is trggered
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <history>
		/// 	[aprasad]	02/16/2011	Intial documentation
		/// </history>
		/// -----------------------------------------------------------------------------
		private void grdUsers_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			switch (e.CommandName)
			{
				case "Delete":
					grdUsers_DeleteCommand(source, e);
					break;
				case "Remove":
					grdUsers_RemoveCommand(source, e);
					break;
				case "Restore":
					grdUsers_RestoreCommand(source, e);
					break;
			}
		}

		private void grdUsers_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				int userId = Int32.Parse(e.CommandArgument.ToString());

				UserInfo user = UserController.GetUserById(UsersPortalId, userId);

				if ((user != null))
				{
					if (UserController.DeleteUser(ref user, true, false))
					{
						UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("UserDeleted", this.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);
					}
					else
					{
						UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("UserDeleteError", this.LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
					}
				}

				if (!string.IsNullOrEmpty(txtSearch.Text))
				{
					Filter = txtSearch.Text;
				}
				BindData(Filter, ddlSearchType.SelectedItem.Value);

				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// grdUsers_RemoveCommand runs when the icon in the delete column is clicked
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <history>
		/// 	[aprasad]	02/16/2011	Intial documentation
		/// </history>
		/// -----------------------------------------------------------------------------
		private void grdUsers_RemoveCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				int userId = Int32.Parse(e.CommandArgument.ToString());

				UserInfo user = UserController.GetUserById(UsersPortalId, userId);

				if ((user != null))
				{
					if (UserController.RemoveUser(user))
					{
						UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("UserRemoved", this.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);
					}
					else
					{
						UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("UserRemoveError", this.LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
					}
				}

				if (!string.IsNullOrEmpty(txtSearch.Text))
				{
					Filter = txtSearch.Text;
				}
				BindData(Filter, ddlSearchType.SelectedItem.Value);

				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// grdUsers_RestoreCommand runs when the icon in the delete column is clicked
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <history>
		/// 	[aprasad]	02/16/2011	Intial documentation
		/// </history>
		/// -----------------------------------------------------------------------------
		private void grdUsers_RestoreCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				int userId = Int32.Parse(e.CommandArgument.ToString());

				UserInfo user = UserController.GetUserById(UsersPortalId, userId);

				if ((user != null))
				{
					if (UserController.RestoreUser(user))
					{
						UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("UserRestored", this.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);
					}
					else
					{
						UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("UserRestoreError", this.LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
					}
				}

				if (!string.IsNullOrEmpty(txtSearch.Text))
				{
					Filter = txtSearch.Text;
				}
				BindData(Filter, ddlSearchType.SelectedItem.Value);

				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		private void grdUsers_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			DataGridItem item = e.Item;
			if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.SelectedItem)
			{
				WebControl imgApprovedDeleted = item.FindControl("imgApprovedDeleted") as WebControl;
				WebControl imgNotApprovedDeleted = item.FindControl("imgNotApprovedDeleted") as WebControl;
				WebControl imgApproved = item.FindControl("imgApproved") as WebControl;
				WebControl imgNotApproved = item.FindControl("imgNotApproved") as WebControl;

				UserInfo user = (UserInfo)item.DataItem;
				if (user != null)
				{
					if (user.IsDeleted)
					{
						foreach (WebControl control in item.Controls)
						{
							control.Attributes.Remove("class");
							control.Attributes.Add("class", "NormalDeleted");
						}
						if (imgApprovedDeleted != null && user.Membership.Approved)
						{
							imgApprovedDeleted.Visible = true;
						}
						else if (imgNotApprovedDeleted != null && !user.Membership.Approved)
						{
							imgNotApprovedDeleted.Visible = true;
						}
					}
					else
					{
						if (imgApproved != null && user.Membership.Approved)
						{
							imgApproved.Visible = true;
						}
						else if (imgNotApproved != null && !user.Membership.Approved)
						{
							imgNotApproved.Visible = true;
						}
					}
				}

				System.Web.UI.Control imgColumnControl = item.Controls[0].Controls[0];
				if (imgColumnControl is HyperLink)
				{
					HyperLink editLink = (HyperLink)imgColumnControl;
					editLink.Visible = !user.IsInRole(PortalSettings.AdministratorRoleName) || (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName));
				}
				imgColumnControl = item.Controls[1].Controls[0];
				if (imgColumnControl is ImageButton)
				{
					ImageButton delImage = (ImageButton)imgColumnControl;
					delImage.Visible = IsCommandAllowed(user, "Delete");

				}
				imgColumnControl = item.Controls[2].Controls[0];
				if (imgColumnControl is HyperLink)
				{
					HyperLink rolesLink = (HyperLink)imgColumnControl;
					rolesLink.Visible = !user.IsInRole(PortalSettings.AdministratorRoleName) || (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName));
				}
				imgColumnControl = item.Controls[3].FindControl("imgOnline");
				if (imgColumnControl is System.Web.UI.WebControls.Image)
				{
					System.Web.UI.WebControls.Image userOnlineImage = (System.Web.UI.WebControls.Image)imgColumnControl;
					userOnlineImage.Visible = user.Membership.IsOnLine;
				}

				imgColumnControl = item.Controls[3].Controls[0];
				if (imgColumnControl is ImageButton)
				{
					ImageButton restoreImage = (ImageButton)imgColumnControl;
					restoreImage.Visible = IsCommandAllowed(user, "Restore");
				}

				imgColumnControl = item.Controls[4].Controls[0];
				if (imgColumnControl is ImageButton)
				{
					ImageButton removeImage = (ImageButton)imgColumnControl;
					removeImage.Visible = IsCommandAllowed(user, "Remove");
				}
			}
		}
		public ModuleActionCollection ModuleActions
		{
			get
			{
				ModuleActionCollection Actions = new ModuleActionCollection();
				string[] FilterParams = new string[String.IsNullOrEmpty(txtSearch.Text.Trim()) ? 2 : 3];
				if (String.IsNullOrEmpty(txtSearch.Text.Trim()))
				{
					FilterParams.SetValue("filter=" + Filter, 0);
					FilterParams.SetValue("currentpage=" + CurrentPage, 1);
				}
				else
				{
					FilterParams.SetValue("filter=" + txtSearch.Text, 0);
					FilterParams.SetValue("filterproperty=" + ddlSearchType == null ? "" : ddlSearchType.SelectedValue.ToString(), 1);
					FilterParams.SetValue("currentpage=" + CurrentPage, 2);
				}
				Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, SecurityAccessLevel.Edit, true, false);
				Actions.Add(GetNextActionID(), Localization.GetString("RemoveDeleted.Action", LocalResourceFile),
				            ModuleActionType.AddContent, "Remove", "delete.gif", "",
				            "confirm('" + ClientAPI.GetSafeJSString(Localization.GetString("RemoveItems.Confirm")) + "')", true,
				            SecurityAccessLevel.Edit, true, false);
				if (!IsSuperUser)
				{
					Actions.Add(GetNextActionID(), Localization.GetString("DeleteUnAuthorized.Action", LocalResourceFile), ModuleActionType.AddContent, "Delete", "action_delete.gif", "", "confirm('" + ClientAPI.GetSafeJSString(Localization.GetString("DeleteItems.Confirm")) + "')", true, SecurityAccessLevel.Edit, true,
					false);
				}
				if (ProfileProviderConfig.CanEditProviderProperties)
				{
					Actions.Add(GetNextActionID(), Localization.GetString("ManageProfile.Action", LocalResourceFile), ModuleActionType.AddContent, "", "icon_profile_16px.gif", EditUrl("ManageProfile"), false, SecurityAccessLevel.Edit, true, false);
				}
				Actions.Add(GetNextActionID(), Localization.GetString("UserSettings.Action", LocalResourceFile), ModuleActionType.AddContent, "", "settings.gif", EditUrl("UserSettings"), false, SecurityAccessLevel.Edit, true, false);
				return Actions;
			}
		}
	}
}
